home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib / tk / text.man < prev    next >
Encoding:
Text File  |  1992-08-24  |  37.3 KB  |  983 lines

  1. '\"
  2. '\" Copyright 1992 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. '\" $Header: /user6/ouster/wish/man/RCS/text.man,v 1.9 92/08/06 09:04:31 ouster Exp $ SPRITE (Berkeley)
  11. '/" 
  12. .\" The definitions below are for supplemental macros used in Sprite
  13. .\" manual entries.
  14. .\"
  15. .\" .HS name section [date [version]]
  16. .\"    Replacement for .TH in other man pages.  See below for valid
  17. .\"    section names.
  18. .\"
  19. .\" .AP type name in/out [indent]
  20. .\"    Start paragraph describing an argument to a library procedure.
  21. .\"    type is type of argument (int, etc.), in/out is either "in", "out",
  22. .\"    or "in/out" to describe whether procedure reads or modifies arg,
  23. .\"    and indent is equivalent to second arg of .IP (shouldn't ever be
  24. .\"    needed;  use .AS below instead)
  25. .\"
  26. .\" .AS [type [name]]
  27. .\"    Give maximum sizes of arguments for setting tab stops.  Type and
  28. .\"    name are examples of largest possible arguments that will be passed
  29. .\"    to .AP later.  If args are omitted, default tab stops are used.
  30. .\"
  31. .\" .BS
  32. .\"    Start box enclosure.  From here until next .BE, everything will be
  33. .\"    enclosed in one large box.
  34. .\"
  35. .\" .BE
  36. .\"    End of box enclosure.
  37. .\"
  38. .\" .VS
  39. .\"    Begin vertical sidebar, for use in marking newly-changed parts
  40. .\"    of man pages.
  41. .\"
  42. .\" .VE
  43. .\"    End of vertical sidebar.
  44. .\"
  45. .\" .DS
  46. .\"    Begin an indented unfilled display.
  47. .\"
  48. .\" .DE
  49. .\"    End of indented unfilled display.
  50. .\"
  51. '\"    # Heading for Sprite man pages
  52. .de HS
  53. .if '\\$2'cmds'       .TH \\$1 1 \\$3 \\$4
  54. .if '\\$2'lib'        .TH \\$1 3 \\$3 \\$4
  55. .if '\\$2'tcl'        .TH \\$1 3 \\$3 \\$4
  56. .if '\\$2'tk'         .TH \\$1 3 \\$3 \\$4
  57. .if t .wh -1.3i ^B
  58. .nr ^l \\n(.l
  59. .ad b
  60. ..
  61. '\"    # Start an argument description
  62. .de AP
  63. .ie !"\\$4"" .TP \\$4
  64. .el \{\
  65. .   ie !"\\$2"" .TP \\n()Cu
  66. .   el          .TP 15
  67. .\}
  68. .ie !"\\$3"" \{\
  69. .ta \\n()Au \\n()Bu
  70. \&\\$1    \\fI\\$2\\fP    (\\$3)
  71. .\".b
  72. .\}
  73. .el \{\
  74. .br
  75. .ie !"\\$2"" \{\
  76. \&\\$1    \\fI\\$2\\fP
  77. .\}
  78. .el \{\
  79. \&\\fI\\$1\\fP
  80. .\}
  81. .\}
  82. ..
  83. '\"    # define tabbing values for .AP
  84. .de AS
  85. .nr )A 10n
  86. .if !"\\$1"" .nr )A \\w'\\$1'u+3n
  87. .nr )B \\n()Au+15n
  88. .\"
  89. .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
  90. .nr )C \\n()Bu+\\w'(in/out)'u+2n
  91. ..
  92. '\"    # BS - start boxed text
  93. '\"    # ^y = starting y location
  94. '\"    # ^b = 1
  95. .de BS
  96. .br
  97. .mk ^y
  98. .nr ^b 1u
  99. .if n .nf
  100. .if n .ti 0
  101. .if n \l'\\n(.lu\(ul'
  102. .if n .fi
  103. ..
  104. '\"    # BE - end boxed text (draw box now)
  105. .de BE
  106. .nf
  107. .ti 0
  108. .mk ^t
  109. .ie n \l'\\n(^lu\(ul'
  110. .el \{\
  111. .\"    Draw four-sided box normally, but don't draw top of
  112. .\"    box if the box started on an earlier page.
  113. .ie !\\n(^b-1 \{\
  114. \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  115. .\}
  116. .el \}\
  117. \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  118. .\}
  119. .\}
  120. .fi
  121. .br
  122. .nr ^b 0
  123. ..
  124. '\"    # VS - start vertical sidebar
  125. '\"    # ^Y = starting y location
  126. '\"    # ^v = 1 (for troff;  for nroff this doesn't matter)
  127. .de VS
  128. .mk ^Y
  129. .ie n 'mc \s12\(br\s0
  130. .el .nr ^v 1u
  131. ..
  132. '\"    # VE - end of vertical sidebar
  133. .de VE
  134. .ie n 'mc
  135. .el \{\
  136. .ev 2
  137. .nf
  138. .ti 0
  139. .mk ^t
  140. \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
  141. .sp -1
  142. .fi
  143. .ev
  144. .\}
  145. .nr ^v 0
  146. ..
  147. '\"    # Special macro to handle page bottom:  finish off current
  148. '\"    # box/sidebar if in box/sidebar mode, then invoked standard
  149. '\"    # page bottom macro.
  150. .de ^B
  151. .ev 2
  152. 'ti 0
  153. 'nf
  154. .mk ^t
  155. .if \\n(^b \{\
  156. .\"    Draw three-sided box if this is the box's first page,
  157. .\"    draw two sides but no top otherwise.
  158. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  159. .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  160. .\}
  161. .if \\n(^v \{\
  162. .nr ^x \\n(^tu+1v-\\n(^Yu
  163. \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
  164. .\}
  165. .bp
  166. 'fi
  167. .ev
  168. .if \\n(^b \{\
  169. .mk ^y
  170. .nr ^b 2
  171. .\}
  172. .if \\n(^v \{\
  173. .mk ^Y
  174. .\}
  175. ..
  176. '\"    # DS - begin display
  177. .de DS
  178. .RS
  179. .nf
  180. .sp
  181. ..
  182. '\"    # DE - end display
  183. .de DE
  184. .fi
  185. .RE
  186. .sp .5
  187. ..
  188. .HS text cmds
  189. .BS
  190. '\" Note:  do not modify the .SH NAME line immediately below!
  191. .SH NAME
  192. text \- Create and manipulate text widgets
  193. .SH SYNOPSIS
  194. \fBtext\fI \fIpathName \fR?\fIoptions\fR?
  195. .SH "STANDARD OPTIONS"
  196. .LP
  197. .nf
  198. .ta 4c 8c 12c
  199. \fBbackground\fR    \fBforeground\fR    \fBinsertWidth\fR    \fBselectBorderWidth\fR
  200. \fBborderWidth\fR    \fBinsertBackground\fR    \fBpadX\fR    \fBselectForeground\fR
  201. \fBcursor\fR    \fBinsertBorderWidth\fR    \fBpadY\fR    \fBsetGrid\fR
  202. \fBexportSelection\fR    \fBinsertOffTime\fR    \fBrelief\fR    \fByScrollCommand\fR
  203. \fBfont\fR    \fBinsertOnTime\fR    \fBselectBackground\fR
  204. .fi
  205. .LP
  206. See the ``options'' manual entry for details on the standard options.
  207. .SH "WIDGET-SPECIFIC OPTIONS"
  208. .LP
  209. .nf
  210. Name:    \fBheight\fR
  211. Class:    \fBHeight\fR
  212. Command-Line Switch:    \fB\-height\fR
  213. .fi
  214. .IP
  215. Specifies the desired height for the window, in units of characters.
  216. Must be at least one.
  217. .LP
  218. .nf
  219. Name:    \fBstate\fR
  220. Class:    \fBState\fR
  221. Command-Line Switch:    \fB\-state\fR
  222. .fi
  223. .IP
  224. Specifies one of two states for the text:  \fBnormal\fR or \fBdisabled\fR.
  225. If the text is disabled then characters may not be inserted or deleted
  226. and no insertion cursor will be displayed, even if the input focus is
  227. in the widget.
  228. .LP
  229. .nf
  230. Name:    \fBwidth\fR
  231. Class:    \fBWidth\fR
  232. Command-Line Switch:    \fB\-width\fR
  233. .fi
  234. .IP
  235. Specifies the desired width for the window in units of characters.
  236. If the font doesn't have a uniform width then the width of the
  237. character ``0'' is used in translating from character units to
  238. screen units.
  239. .LP
  240. .nf
  241. Name:    \fBwrap\fR
  242. Class:    \fBWrap\fR
  243. Command-Line Switch:    \fB\-wrap\fR
  244. .fi
  245. .IP
  246. Specifies how to handle lines in the text that are too long to be
  247. displayed in a single line of the text's window.
  248. The value must be \fBnone\fR or \fBchar\fR or \fBword\fR.
  249. A wrap mode of \fBnone\fR means that each line of text appears as
  250. exactly one line on the screen;  extra characters that don't fit
  251. on the screen are not displayed.
  252. In the other modes each line of text will be broken up into several
  253. screen lines if necessary to keep all the characters visible.
  254. In \fBchar\fR mode a screen line break may occur after any character;
  255. in \fBword\fR mode a line break will only be made at word boundaries.
  256. .BE
  257.  
  258. .SH DESCRIPTION
  259. .PP
  260. The \fBtext\fR command creates a new window (given by the
  261. \fIpathName\fR argument) and makes it into a text widget.
  262. Additional
  263. options, described above, may be specified on the command line
  264. or in the option database
  265. to configure aspects of the text such as its default background color
  266. and relief.  The \fBtext\fR command returns the
  267. path name of the new window.
  268. .PP
  269. A text widget displays one or more lines of text and allows that
  270. text to be edited.
  271. Text widgets support three different kinds of annotations on the
  272. text, called tags, marks, and windows.
  273. Tags allow different portions of the text
  274. to be displayed with different fonts and colors.
  275. In addition, Tcl commands can be associated with tags so
  276. that commands are invoked when particular actions such as keystrokes
  277. and mouse button presses occur in particular ranges of the text.
  278. See TAGS below for more details.
  279. .PP
  280. The second form of annotation consists of marks, which are floating
  281. markers in the text.
  282. Marks are used to keep track of various interesting positions in the
  283. text as it is edited.
  284. See MARKS below for more details.
  285. .PP
  286. The third form of annotation allows arbitrary windows to be displayed
  287. in the text widget.
  288. See WINDOWS below for more details.
  289.  
  290. .SH INDICES
  291. .PP
  292. Many of the widget commands for texts take one or more indices
  293. as arguments.
  294. An index is a string used to indicate a particular place within
  295. a text, such as a place to insert characters or one endpoint of a
  296. range of characters to delete.
  297. Indices have the syntax
  298. .IP
  299. \fIbase modifier modifier modifier ...\fR
  300. .LP
  301. Where \fIbase\fR gives a starting point and the \fImodifier\fRs
  302. adjust the index from the starting point (e.g. move forward or
  303. backward one character).  Every index must contain a \fIbase\fR,
  304. but the \fImodifier\fRs are optional.
  305. .LP
  306. The \fIbase\fR for an index must have one of the following forms:
  307. .TP 12
  308. \fIline\fB.\fIchar\fR
  309. Indicates \fIchar\fR'th character on line \fIline\fR.
  310. Lines are numbered from 1 for consistency with other UNIX programs
  311. that use this numbering scheme.
  312. Within a line, characters are numbered from 0.
  313. .TP 12
  314. \fB@\fIx\fB,\fIy\fR
  315. Indicates the character that covers the pixel whose x and y coordinates
  316. within the text's window are \fIx\fR and \fIy\fR.
  317. .TP 12
  318. \fBend\fR
  319. Indicates the last character in the text, which is always a newline
  320. character.
  321. .TP 12
  322. \fImark\fR
  323. Indicates the character just after the mark whose name is \fImark\fR.
  324. .TP 12
  325. \fItag\fB.first\fR
  326. Indicates the first character in the text that has been tagged with
  327. \fItag\fR.
  328. This form generates an error if no characters are currently tagged
  329. with \fItag\fR.
  330. .TP 12
  331. \fItag\fB.last\fR
  332. Indicates the character just after the last one in the text that has
  333. been tagged with \fItag\fR.
  334. This form generates an error if no characters are currently tagged
  335. with \fItag\fR.
  336. .LP
  337. If modifiers follow the base index, each one of them must have one
  338. of the forms listed below.  Keywords such as \fBchars\fR and \fBwordend\fR
  339. may be abbreviated as long as the abbreviation is unambiguous.
  340. .TP
  341. \fB+ \fIcount\fB chars\fR
  342. Adjust the index forward by \fIcount\fR characters, moving to later
  343. lines in the text if necessary.  If there are fewer than \fIcount\fR
  344. characters in the text after the current index, then set the index
  345. to the last character in the text.
  346. Spaces on either side of \fIcount\fR are optional.
  347. .TP
  348. \fB\- \fIcount\fB chars\fR
  349. Adjust the index backward by \fIcount\fR characters, moving to earlier
  350. lines in the text if necessary.  If there are fewer than \fIcount\fR
  351. characters in the text before the current index, then set the index
  352. to the first character in the text.
  353. Spaces on either side of \fIcount\fR are optional.
  354. .TP
  355. \fB+ \fIcount\fB lines\fR
  356. Adjust the index forward by \fIcount\fR lines, retaining the same
  357. character position within the line.  If there are fewer than \fIcount\fR
  358. lines after the line containing the current index, then set the index
  359. to refer to the same character position on the last line of the text.
  360. Then, if the line is not long enough to contain a character at the indicated
  361. character position, adjust the character position to refer to the last
  362. character of the line (the newline).
  363. Spaces on either side of \fIcount\fR are optional.
  364. .TP
  365. \fB\- \fIcount\fB lines\fR
  366. Adjust the index backward by \fIcount\fR lines, retaining the same
  367. character position within the line.  If there are fewer than \fIcount\fR
  368. lines before the line containing the current index, then set the index
  369. to refer to the same character position on the first line of the text.
  370. Then, if the line is not long enough to contain a character at the indicated
  371. character position, adjust the character position to refer to the last
  372. character of the line (the newline).
  373. Spaces on either side of \fIcount\fR are optional.
  374. .TP
  375. \fBlinestart\fR
  376. Adjust the index to refer to the first character on the line.
  377. .TP
  378. \fBlineend\fR
  379. Adjust the index to refer to the last character on the line (the newline).
  380. .TP
  381. \fBwordstart\fR
  382. Adjust the index to refer to the first character of the word containing
  383. the current index.  A word consists of any number of adjacent characters
  384. that are letters, digits, or underscores, or a single character that
  385. is not one of these.
  386. .TP
  387. \fBwordend\fR
  388. Adjust the index to refer to the character just after the last one of the
  389. word containing the current index.  If the current index refers to the last
  390. character of the text then it is not modified.
  391. .LP
  392. If more than one modifier is present then they are applied in
  393. left-to-right order.  For example, the index ``\fBend \- 1 chars\fR''
  394. refers to the next-to-last character in the text and
  395. ``\fBinsert wordstart \- 1 c\fR'' refers to the character just before
  396. the first one in the word containing the insertion cursor.
  397.  
  398. .SH TAGS
  399. .PP
  400. The first form of annotation in text widgets is a tag.
  401. A tag is a textual string that is associated with some of the characters
  402. in a text.
  403. There may be any number of tags associated with characters in a
  404. text.
  405. Each tag may refer to a single character, a range of characters, or
  406. several ranges of characters.
  407. An individual character may have any number of tags associated with it.
  408. .PP
  409. A priority order is defined among tags, and this order is used in
  410. implementing some of the tag-related functions described below.
  411. When a tag is defined (by associating it with characters or setting
  412. its display options or binding commands to it), it is given
  413. a priority higher than any existing tag.
  414. The priority order of tags may be redefined using the
  415. ``\fIpathName \fBtag raise\fR'' and ``\fIpathName \fBtag lower\fR''
  416. widget commands.
  417. .PP
  418. Tags serve three purposes in text widgets.
  419. First, they control the way information is displayed on the screen.
  420. By default, characters are displayed as determined by the
  421. \fBbackground\fR, \fBfont\fR, and \fBforeground\fR options for the
  422. text widget.
  423. However, display options may be associated with individual tags
  424. using the ``\fIpathName \fBtag configure\fR'' widget command.
  425. If a character has been tagged, then the display options associated
  426. with the tag override the default display style.
  427. The following options are currently supported for tags:
  428. .TP
  429. \fB\-background \fIcolor\fR
  430. \fIColor\fR specifies the background color to use for characters
  431. associated with the tag.
  432. It may have any of the forms accepted by \fBTk_GetColor\fR.
  433. .TP
  434. \fB\-bgstipple \fIbitmap\fR
  435. \fIBitmap\fR specifies a bitmap that is used as a stipple pattern
  436. for the background.
  437. It may have any of the forms accepted by \fBTk_GetBitmap\fR.
  438. If \fIbitmap\fR hasn't been specified, or if it is specified
  439. as an empty string, then a solid fill will be used for the
  440. background.
  441. .TP
  442. \fB\-borderwidth \fIpixels\fR
  443. \fIPixels\fR specifies the width of a 3-D border to draw around
  444. the background.
  445. It may have any of the forms accepted by \fBTk_GetPixels\fR.
  446. This option is used in conjunction with the \fB\-relief\fR
  447. option to give a 3-D appearance to the background for characters;
  448. it is ignored unless the \fB\-background\fR option
  449. has been set for the tag.
  450. .TP
  451. \fB\-fgstipple \fIbitmap\fR
  452. \fIBitmap\fR specifies a bitmap that is used as a stipple pattern
  453. when drawing text and other foreground information such as
  454. underlines.
  455. It may have any of the forms accepted by \fBTk_GetBitmap\fR.
  456. If \fIbitmap\fR hasn't been specified, or if it is specified
  457. as an empty string, then a solid fill will be used.
  458. .TP
  459. \fB\-font \fIfontName\fR
  460. \fIFontName\fR is the name of a font to use for drawing characters.
  461. It may have any of the forms accepted by \fBTk_GetFontStruct\fR.
  462. .TP
  463. \fB\-foreground \fIcolor\fR
  464. \fIColor\fR specifies the color to use when drawing text and other
  465. foreground information such as underlines.
  466. It may have any of the forms accepted by \fBTk_GetColor\fR.
  467. .TP
  468. \fB\-relief \fIrelief\fR
  469. \fIRelief specifies the 3-D relief to use for drawing backgrounds,
  470. in any of the forms accepted by \fBTk_GetRelief\fR.
  471. This option is used in conjunction with the \fB\-borderwidth\fR
  472. option to give a 3-D appearance to the background for characters;
  473. it is ignored unless the \fB\-background\fR option
  474. has been set for the tag.
  475. .TP
  476. \fB\-underline \fIboolean\fR
  477. \fIBoolean\fR specifies whether or not to draw an underline underneath
  478. characters.
  479. It may have any of the forms accepted by \fBTk_GetBoolean\fR.
  480. .PP
  481. If a character has several tags associated with it, and if their
  482. display options conflict, then the options of the highest priority
  483. tag are used.
  484. If a particular display option hasn't been specified for a
  485. particular tag, or if it is specified as an empty string, then
  486. that option will never be used;  the next-highest-priority
  487. tag's option will used instead.
  488. If no tag specifies a particular display optionl, then the default
  489. style for the widget will be used.
  490. .PP
  491. The second purpose for tags is event bindings.
  492. You can associate bindings with a tag in much the same way you can
  493. associate bindings with a widget class:  whenever particular X
  494. events occur on characters with the given tag, a given
  495. Tcl command will be executed.
  496. Tag bindings can be used to give behaviors to ranges of characters;
  497. among other things, this allows hypertext-like
  498. features to be implemented.
  499. For details, see the description of the \fBtag bind\fR widget
  500. command below.
  501. .PP
  502. The third use for tags is in managing the selection.
  503. See THE SELECTION below.
  504.  
  505. .SH MARKS
  506. .PP
  507. The second form of annotation in text widgets is a mark.
  508. Marks are used for remembering particular places in a text.
  509. They are something like tags, in that they have names and
  510. they refer to places in the file, but a mark isn't associated
  511. with particular characters.
  512. Instead, a mark is associated with the gap between two characters.
  513. Only a single position may be associated with a mark at any given
  514. time.
  515. If the characters around a mark are deleted the mark will still
  516. remain;  it will just have new neighbor characters.
  517. In contrast, if the characters containing a tag are deleted then
  518. the tag will no longer have an association with characters in
  519. the file.
  520. Marks may be manipulated with the ``\fIpathName \fBmark\fR'' widget
  521. command, and their current locations may be determined by using the
  522. mark name as an index in widget commands.
  523. .PP
  524. The name space for marks is different from that for tags:  the
  525. same name may be used for both a mark and a tag, but they will refer
  526. to different things.
  527. .PP
  528. Two marks have special significance.
  529. First, the mark \fBinsert\fR is associated with the insertion cursor,
  530. as described under THE INSERTION CURSOR below.
  531. Second, the mark \fBcurrent\fR is associated with the character
  532. closest to the mouse and is adjusted automatically to track the
  533. mouse position and any changes to the text in the widget (one
  534. exception:  \fBcurrent\fR is not updated in response to mouse
  535. motions if a mouse button is down;  the update will be deferred
  536. until all mouse buttons have been released).
  537. Neither of these special marks may be unset.
  538.  
  539. .SH WINDOWS
  540. .PP
  541. The third form of annotation in text widgets is a window.
  542. Window support isn't implemented yet, but when it is it will be
  543. described here.
  544.  
  545. .SH THE SELECTION
  546. .PP
  547. Text widgets support the standard X selection.
  548. Selection support is implemented via tags.
  549. If the \fBexportSelection\fR option for the text widget is true
  550. then the \fBsel\fR tag will be associated with the selection:
  551. .IP [1]
  552. Whenever characters are tagged with \fBsel\fR the text widget
  553. will claim ownership of the selection.
  554. .IP [2]
  555. Attempts to retrieve the
  556. selection will be serviced by the text widget, returning all the
  557. charaters with the \fBsel\fR tag.
  558. .IP [3]
  559. If the selection is claimed away by another application or by another
  560. window within this application, then the \fBsel\fR tag will be removed
  561. from all characters in the text.
  562. .PP
  563. The \fBsel\fR tag is automatically defined when a text widget is
  564. created, and it may not be deleted with the ``\fIpathName \fBtag delete\fR''
  565. widget command.  Furthermore, the \fBselectBackground\fR,
  566. \fBselectBorderWidth\fR, and \fBselectForeground\fR options for
  567. the text widget are tied to the \fB\-background\fR,
  568. \fB\-borderwidth\fR, and \fB\-foreground\fR options for the \fBsel\fR
  569. tag:  changes in either will automatically be reflected in the
  570. other.
  571.  
  572. .SH THE INSERTION CURSOR
  573. .PP
  574. The mark named \fBinsert\fR has special significance in text widgets.
  575. It is defined automatically when a text widget is created and it
  576. may not be unset with the ``\fIpathName \fBmark unset\fR'' widget
  577. command.
  578. The \fBinsert\fR mark represents the position of the insertion
  579. cursor, and the insertion cursor will automatically be drawn at
  580. this point whenever the text widget has the input focus.
  581.  
  582. .SH "WIDGET COMMAND"
  583. .PP
  584. The \fBtext\fR command creates a new Tcl command whose
  585. name is the same as the path name of the text's window.  This
  586. command may be used to invoke various
  587. operations on the widget.  It has the following general form:
  588. .DS C
  589. \fIpathName option \fR?\fIarg arg ...\fR?
  590. .DE
  591. \fIPathName\fR is the name of the command, which is the same as
  592. the text widget's path name.  \fIOption\fR and the \fIarg\fRs
  593. determine the exact behavior of the command.  The following
  594. commands are possible for text widgets:
  595. .TP
  596. \fIpathName \fBcompare\fR \fIindex1 op index2\fR
  597. Compares the indices given by \fIindex1\fR and \fIindex2\fR according
  598. to the relational operator given by \fIop\fR, and returns 1 if
  599. the relationship is satisfied and 0 if it isn't.
  600. \fIOp\fR must be one of the operators <, <=, ==, >=, >, or !=.
  601. If \fIop\fR is == then 1 is returned if the two indices refer to
  602. the same character, if \fIop\fR is < then 1 is returned if \fIindex1\fR
  603. refers to an earlier character in the text than \fIindex2\fR, and
  604. so on.
  605. .TP
  606. \fIpathName \fBconfigure\fR ?\fIoption\fR? \fI?value option value ...\fR?
  607. Query or modify the configuration options of the widget.
  608. If no \fIoption\fR is specified, returns a list describing all of
  609. the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
  610. information on the format of this list).  If \fIoption\fR is specified
  611. with no \fIvalue\fR, then the command returns a list describing the
  612. one named option (this list will be identical to the corresponding
  613. sublist of the value returned if no \fIoption\fR is specified).  If
  614. one or more \fIoption\-value\fR pairs are specified, then the command
  615. modifies the given widget option(s) to have the given value(s);  in
  616. this case the command returns an empty string.
  617. \fIOption\fR may have any of the values accepted by the \fBtext\fR
  618. command.
  619. .TP
  620. \fIpathName \fBdebug \fR?\fIboolean\fR?
  621. If \fIboolean\fR is specified, then it must have one of the true or
  622. false values accepted by Tcl_GetBoolean.
  623. If the value is a true one then internal consistency checks will be
  624. turned on in the B-tree code associated with text widgets.
  625. If \fIboolean\fR has a false value then the debugging checks will
  626. be turned off.
  627. In either case the command returns an empty string.
  628. If \fIboolean\fR is not specified then the command returns \fBon\fR
  629. or \fBoff\fR to indicate whether or not debugging is turned on.
  630. There is a single debugging switch shared by all text widgets:  turning
  631. debugging on or off in any widget turns it on or off for all widgets.
  632. For widgets with large amounts of text, the consistency checks may
  633. cause a noticeable slow-down.
  634. .TP
  635. \fIpathName \fBdelete \fIindex1 \fR?\fIindex2\fR?
  636. Delete a range of characters from the text.
  637. If both \fIindex1\fR and \fIindex2\fR are specified, then delete
  638. all the characters starting with the one given by \fIindex1\fR
  639. and stopping just before \fIindex2\fR (i.e. the character at
  640. \fIindex2\fR is not deleted).
  641. If \fIindex2\fR doesn't specify a position later in the text
  642. than \fIindex1\fR then no characters are deleted.
  643. If \fIindex2\fR isn't specified then the single character at
  644. \fIindex1\fR is deleted.
  645. It is not allowable to delete characters in a way that would leave
  646. the text without a newline as the last character.
  647. The command returns an empty string.
  648. .TP
  649. \fIpathName \fBget \fIindex1 \fR?\fIindex2\fR?
  650. Return a range of characters from the text.
  651. The return value will be all the characters in the text starting
  652. with the one whose index is \fIindex1\fR and ending just before
  653. the one whose index is \fIindex2\fR (the character at \fIindex2\fR
  654. will not be returned).
  655. If \fIindex2\fR is omitted then the single character at \fIindex1\fR
  656. is returned.
  657. If there are no characters in the specified range (e.g. \fIindex1\fR
  658. is past the end of the file or \fIindex2\fR is less than or equal
  659. to \fIindex1\fR) then an empty string is returned.
  660. .TP
  661. \fIpathName \fBindex \fIindex\fR
  662. Returns the position corresponding to \fIindex\fR in the form
  663. \fIline.char\fR where \fIline\fR is the line number and \fIchar\fR
  664. is the character number.
  665. \fIIndex\fR may have any of the forms described under INDICES above.
  666. .TP
  667. \fIpathName \fBinsert \fIindex chars
  668. Inserts \fIchars\fR into the text just before the character at
  669. \fIindex\fR and returns an empty string.
  670. It is not possible to insert characters after the last newline
  671. of the text.
  672. .TP
  673. \fIpathName \fBmark \fIoption \fR?\fIarg arg ...\fR?
  674. This command is used to manipulate marks.  The exact behavior of
  675. the command depends on the \fIoption\fR argument that follows
  676. the \fBmark\fR argument.  The following forms of the command
  677. are currently supported:
  678. .RS
  679. .TP
  680. \fIpathName \fBmark names\fR
  681. Returns a list whose elements are the names of all the marks that
  682. are currently set.
  683. .TP
  684. \fIpathName \fBmark set \fImarkName index\fR
  685. Sets the mark named \fImarkName\fR to a position just before the
  686. character at \fIindex\fR.
  687. If \fImarkName\fR already exists, it is moved from its old position;
  688. if it doesn't exist, a new mark is created.
  689. This command returns an empty string.
  690. .TP
  691. \fIpathName \fBmark unset \fImarkName \fR?\fImarkName markName ...\fR?
  692. Remove the mark corresponding to each of the \fImarkName\fR arguments.
  693. The removed marks will not be usable in indices and will not be
  694. returned by future calls to ``\fIpathName \fBmark names\fR''.
  695. This command returns an empty string.
  696. .RE
  697. .TP
  698. \fIpathName \fBscan\fR \fIoption args\fR
  699. This command is used to implement scanning on texts.  It has
  700. two forms, depending on \fIoption\fR:
  701. .RS
  702. .TP
  703. \fIpathName \fBscan mark \fIy\fR
  704. Records \fIy\fR and the current view in the text window;  used in
  705. conjunction with later \fBscan dragto\fR commands.  Typically this
  706. command is associated with a mouse button press in the widget.  It
  707. returns an empty string.
  708. .TP
  709. \fIpathName \fBscan dragto \fIy\fR
  710. This command computes the difference between its \fIy\fR argument
  711. and the \fIy\fR argument to the last \fBscan mark\fR command for
  712. the widget.  It then adjusts the view up or down by 10 times the
  713. difference in y-coordinates.  This command is typically associated
  714. with mouse motion events in the widget, to produce the effect of
  715. dragging the text at high speed through the window.  The return
  716. value is an empty string.
  717. .RE
  718. .TP
  719. \fIpathName \fBtag \fIoption \fR?\fIarg arg ...\fR?
  720. This command is used to manipulate tags.  The exact behavior of the
  721. command depends on the \fIoption\fR argument that follows the
  722. \fBtag\fR argument.  The following forms of the command are currently
  723. supported:
  724. .RS
  725. .TP
  726. \fIpathName \fBtag add \fItagName index1 \fR?\fIindex2\fR?
  727. Associate the tag \fItagName\fR with all of the characters starting
  728. with \fIindex1\fR and ending just before
  729. \fIindex2\fR (the character at \fIindex2\fR isn't tagged).
  730. If \fIindex2\fR is omitted then the single character at
  731. \fIindex1\fR is tagged.
  732. If there are no characters in the specified range (e.g. \fIindex1\fR
  733. is past the end of the file or \fIindex2\fR is less than or equal
  734. to \fIindex1\fR) then the command has no effect.
  735. This command returns an empty string.
  736. .TP
  737. \fIpathName \fBtag bind \fItagName\fR ?\fIsequence\fR? ?\fIcommand\fR?
  738. This command associates \fIcommand\fR with the tag given by
  739. \fItagName\fR.
  740. Whenever the event sequence given by \fIsequence\fR occurs for a
  741. character that has been tagged with \fItagName\fR,
  742. the command will be invoked.
  743. This widget command is similar to the \fBbind\fR command except that
  744. it operates on characters in a text rather than entire widgets.
  745. See the \fBbind\fR manual entry for complete details
  746. on the syntax of \fIsequence\fR and the substitutions performed
  747. on \fIcommand\fR before invoking it.
  748. If all arguments are specified then a new binding is created, replacing
  749. any existing binding for the same \fIsequence\fR and \fItagName\fR
  750. (if the first character of \fIcommand\fR is ``+'' then \fIcommand\fR
  751. augments an existing binding rather than replacing it).
  752. In this case the return value is an empty string.
  753. If \fIcommand\fR is omitted then the command returns the \fIcommand\fR
  754. associated with \fItagName\fR and \fIsequence\fR (an error occurs
  755. if there is no such binding).
  756. If both \fIcommand\fR and \fIsequence\fR are omitted then the command
  757. returns a list of all the sequences for which bindings have been
  758. defined for \fItagName\fR.
  759. .RS
  760. .LP
  761. The only events for which bindings may be specified are those related
  762. to the mouse and keyboard, such as \fBEnter\fR, \fBLeave\fR,
  763. \fBButtonPress\fR, \fBMotion\fR, and \fBKeyPress\fR.
  764. Event bindings for a text widget use the \fBcurrent\fR mark
  765. described under MARKS above.
  766. \fBEnter\fR events trigger for a character when it
  767. becomes the current character (i.e. the \fBcurrent\fR mark moves
  768. to just in front of that character).
  769. \fBLeave\fR events trigger for a character when it ceases to be
  770. the current item (i.e. the \fBcurrent\fR mark moves away from
  771. that character, or the character is deleted).
  772. These events are different than \fBEnter\fR and \fBLeave\fR
  773. events for windows.
  774. Mouse and keyboard events are directed to the current character.
  775. .LP
  776. It is possible for the current character to have multiple tags,
  777. and for each of them to have a binding for a particular event
  778. sequence.
  779. When this occurs, the binding from the highest priority tag is
  780. used.
  781. If a particular tag doesn't have a binding that matches an
  782. event, then the tag is ignored and tags with lower priority
  783. will be checked.
  784. .LP
  785. If bindings are created for the widget as a whole using the
  786. \fBbind\fR command, then those bindings will supplement the
  787. tag bindings.
  788. This means that a single event can trigger two Tcl scripts,
  789. one for a widget-level binding and one for a tag-level
  790. binding.
  791. .RE
  792. .TP
  793. \fIpathName \fBtag configure \fItagName\fR ?\fIoption\fR? ?\fIvalue\fR? ?\fIoption value ...\fR?
  794. This command is similar to the \fBconfigure\fR widget command except
  795. that it modifies options associated with the tag given by \fItagName\fR
  796. instead of modifying options for the overall text widget.
  797. If no \fIoption\fR is specified, the command returns a list describing
  798. all of the available options for \fItagName\fR (see \fBTk_ConfigureInfo\fR
  799. for information on the format of this list).
  800. If \fIoption\fR is specified with no \fIvalue\fR, then the command returns
  801. a list describing the one named option (this list will be identical to
  802. the corresponding sublist of the value returned if no \fIoption\fR
  803. is specified).
  804. If one or more \fIoption\-value\fR pairs are specified, then the command
  805. modifies the given option(s) to have the given value(s) in \fItagName\fR;
  806. in this case the command returns an empty string.
  807. See TAGS above for details on the options available for tags.
  808. .TP
  809. \fIpathName \fBtag delete \fItagName \fR?\fItagName ...\fR?
  810. Deletes all tag information for each of the \fItagName\fR
  811. arguments.
  812. The command removes the tags from all characters in the file
  813. and also deletes any other information associated with the tags,
  814. such as bindings and display information.
  815. The command returns an empty string.
  816. .TP
  817. \fIpathName\fBtag lower \fItagName \fR?\fIbelowThis\fR?
  818. Changes the priority of tag \fItagName\fR so that it is just lower
  819. in priority than the tag whose name is \fIbelowThis\fR.
  820. If \fIbelowThis\fR is omitted, then \fItagName\fR's priority
  821. is changed to make it lowest priority of all tags.
  822. .TP
  823. \fIpathName \fBtag names \fR?\fIindex\fR?
  824. Returns a list whose elements are the names of all the tags that
  825. are active at the character position given by \fIindex\fR.
  826. If \fIindex\fR is omitted, then the return value will describe
  827. all of the tags that exist for the text (this includes all tags
  828. that have been named in a ``\fIpathName \fBtag\fR'' widget
  829. command but haven't been deleted by a ``\fIpathName \fBtag delete\fR''
  830. widget command, even if no characters are currently marked with
  831. the tag).
  832. The list will be sorted in order from lowest priority to highest
  833. priority.
  834. .TP
  835. \fIpathName \fBtag nextrange \fItagName index1 \fR?\fIindex2\fR?
  836. This command searches the text for a range of characters tagged
  837. with \fItagName\fR where the first character of the range is
  838. no earlier than the character at \fIindex1\fR and no later than
  839. the character just before \fIindex2\fR (a range starting at
  840. \fIindex2\fR will not be considered).
  841. If several matching ranges exist, the first one is chosen.
  842. The command's return value is a list containing
  843. two elements, which are the index of the first character of the
  844. range and the index of the character just after the last one in
  845. the range.
  846. If no matching range is found then the return value is an
  847. empty string.
  848. If \fIindex2\fR is not given then it defaults to the end of the text.
  849. .TP
  850. \fIpathName\fBtag raise \fItagName \fR?\fIaboveThis\fR?
  851. Changes the priority of tag \fItagName\fR so that it is just higher
  852. in priority than the tag whose name is \fIaboveThis\fR.
  853. If \fIaboveThis\fR is omitted, then \fItagName\fR's priority
  854. is changed to make it highest priority of all tags.
  855. .TP
  856. \fIpathName \fBtag ranges \fItagName\fR
  857. Return a list describing all of the ranges of text that have been
  858. tagged with \fItagName\fR.
  859. The list consists of zero or more pairs of elements, with each
  860. pair describing a range of characters that have been tagged
  861. with \fItagName\fR.
  862. The first element of the pair contains the index of the first
  863. character of the range, and the second element of the pair contains
  864. the index of the character just after the last one in the
  865. range.
  866. The list is sorted so that the first tagged range in the text is
  867. described by the first two elements of the list, and so on.
  868. If there are no characters tagged with \fItag\fR then an
  869. empty string is returned.
  870. .TP
  871. \fIpathName \fBtag remove \fItagName index1 \fR?\fIindex2\fR?
  872. Remove the tag \fItagName\fR from all of the characters starting
  873. at \fIindex1\fR and ending just before
  874. \fIindex2\fR (the character at \fIindex2\fR isn't affected).
  875. If \fIindex2\fR is omitted then the single character at
  876. \fIindex1\fR is untagged.
  877. If there are no characters in the specified range (e.g. \fIindex1\fR
  878. is past the end of the file or \fIindex2\fR is less than or equal
  879. to \fIindex1\fR) then the command has no effect.
  880. This command returns an empty string.
  881. .RE
  882. .TP
  883. \fIpathName \fByview \fR?\fB\-pickplace\fR? \fIwhat\fR
  884. This command changes the view in the widget's window so that the line
  885. given by \fIwhat\fR is visible in the window.
  886. \fIWhat\fR may be either an absolute line number, where 0 corresponds
  887. to the first line of the file, or an index with any of the forms
  888. described under INDICES above.
  889. The first form (absolute line number) is used in the commands issued
  890. by scrollbars to control the widget's view.
  891. If the \fB\-pickplace\fR option isn't specified then \fIwhat\fR will
  892. appear at the top of the window.
  893. If \fB\-pickplace\fR is specified then the widget chooses where
  894. \fIwhat\fR appears in the window:
  895. .RS
  896. .IP [1]
  897. If \fIwhat\fR is already visible somewhere in the window then the
  898. command does nothing.
  899. .IP [2]
  900. If \fIwhat\fR is only a few lines off-screen above the window then
  901. it will be positioned at the top of the window.
  902. .IP [3]
  903. If \fIwhat\fR is only a few lines off-screen below the window then
  904. it will be positioned at the bottom of the window.
  905. .IP [4]
  906. Otherwise, \fIwhat\fR will be centered in the window.
  907. .LP
  908. The \fB\-pickplace\fR option is typically used after inserting text
  909. to make sure that the insertion cursor is still visible on the screen.
  910. This command returns an empty string.
  911. .RE
  912.  
  913. .SH BINDINGS
  914. .PP
  915. Tk automatically creates class bindings for texts that give them
  916. the following default behavior:
  917. .IP [1]
  918. Pressing mouse button 1 in an text positions the insertion cursor
  919. just before the character underneath the mouse cursor and sets the
  920. input focus to this widget.
  921. .IP [2]
  922. Dragging with mouse button 1 strokes out a selection between
  923. the insertion cursor and the character under the mouse.
  924. .IP [3]
  925. If you double-press mouse button 1 then the word under the mouse cursor
  926. will be selected, the insertion cursor will be positioned at the
  927. beginning of the word, and dragging the mouse will stroke out a selection
  928. whole words at a time.
  929. .IP [4]
  930. If you triple-press mouse button 1 then the line under the mouse cursor
  931. will be selected, the insertion cursor will be positioned at the
  932. beginning of the line, and dragging the mouse will stroke out a selection
  933. whole line at a time.
  934. .IP [5]
  935. The ends of the selection can be adjusted by dragging with mouse
  936. button 1 while the shift key is down;  this will adjust the end
  937. of the selection that was nearest to the mouse cursor when button
  938. 1 was pressed.  If the selection was made in word or line mode then
  939. it will be adjusted in this same mode.
  940. .IP [6]
  941. The view in the text can be adjusted by dragging with mouse button 2.
  942. .IP [7]
  943. If the input focus is in a text widget and characters are typed on the
  944. keyboard, the characters are inserted just before the insertion cursor.
  945. .IP [8]
  946. Control+h and the Backspace and Delete keys erase the character just
  947. before the insertion cursor.
  948. .IP [9]
  949. Control+v inserts the current selection just before the insertion cursor.
  950. .IP [10]
  951. Control+d deletes the selected characters;  an error occurs if the selection
  952. is not in this widget.
  953. .PP
  954. If the text is disabled using the \fBstate\fR option, then the text's
  955. view can still be adjusted and text in the text can still be selected,
  956. but no insertion cursor will be displayed and no text modifications will
  957. take place.
  958. .PP
  959. The behavior of texts can be changed by defining new bindings for
  960. individual widgets or by redefining the class bindings.
  961.  
  962. .SH "PERFORMANCE ISSUES"
  963. .PP
  964. Text widgets should run efficiently under a variety
  965. of conditions.  The text widget uses about 2-3 bytes of
  966. main memory for each byte of text, so texts containing a megabyte
  967. or more should be practical on most workstations.
  968. Text is represented internally with a modified B-tree structure
  969. that makes operations relatively efficient even with large texts.
  970. Tags are included in the B-tree structure in a way that allows
  971. tags to span large ranges or have many disjoint smaller ranges
  972. without loss of efficiency.
  973. Marks are also implemented in a way that allows large numbers of
  974. marks.
  975. The only known mode of operation where a text widget may not run
  976. efficiently is if it has a very large number of different tags.
  977. Hundreds of tags should be fine, or even a thousand,
  978. but tens of thousands of tags will make texts consume a lot of
  979. memory and run slowly.
  980.  
  981. .SH KEYWORDS
  982. text, widget
  983.